package com.frxuexi.park2304.my

import com.frxuexi.lib_base.http.ApiService
import com.frxuexi.lib_base.mvi.BaseViewModel
import com.frxuexi.lib_base.mvi.RequestType
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class MyViewModel @Inject constructor(val apiService: ApiService):BaseViewModel<MyIntent>(){
    override fun handleIntent(it: MyIntent) {
        when(it){
            is MyIntent.getMyPark->httpRequest(apiService.getParkByUid(it.uid))
            is MyIntent.getMyVisit->httpRequest(apiService.getVisitsByName(it.uname),RequestType.MYVISIT)
            is MyIntent.getMyRepairs->httpRequest(apiService.getRepairsByUname(it.uname),RequestType.MYREPAIR)
            is MyIntent.getMyPatrols->httpRequest(apiService.getMyPatrols(it.uid),RequestType.MYPATROL)
            is MyIntent.getParksByType->httpRequest(apiService.getParksByType(it.type),RequestType.PARKSTATUS)
            is MyIntent.getVisits->httpRequest(apiService.getVisits(),RequestType.MYVISIT)
            is MyIntent.getNews->httpRequest(apiService.getNews(),RequestType.NEWS)
            is MyIntent.updatePark->httpRequest(apiService.updateParkStatus(it.id,it.status),RequestType.UPDATE)
            is MyIntent.rejectVisit->httpRequest(apiService.rejectVisit(it.id),RequestType.UPDATE)
            is MyIntent.approveVisit->httpRequest(apiService.approveVisit(it.id),RequestType.UPDATE)
            is MyIntent.revokeNews->httpRequest(apiService.revokeNews(it.id),RequestType.UPDATE)
        }
    }
}